﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace BitPortal.Utils
{
    public static class GeneralUtils
    {
        public static int ToInt32TryParse(this object input, int catchValue = 0)
        {
            try
            {
                return Convert.ToInt32(input);
            }
            catch { return catchValue; }
        }


        public static long ToInt64TryParse(this object input, long catchValue = 0)
        {
            try
            {
                return Convert.ToInt64(input);
            }
            catch { return catchValue; }
        }

        public static DateTime? ToDateTimeTryParse(this object input, DateTime? catchValue = null)
        {
            try
            {
                
                return Convert.ToDateTime(input);
            }
            catch { return catchValue; }
        }



        public static String ToClearnString(this String str)
        {
            try
            {
                string pattern = "<.*?>";
                str = Regex.Replace(str, pattern, " \n ");
                str = str.Trim();
                return str;
            }
            catch (System.Exception ex)
            {
                return "";
            }
        }
    }
}
